$(function () {
   obj.init();
});
var obj = new function () {
    'use strict';
    return {
        form:null,
        id : null,
        init:function () {
            this.form = new xhForm($('#xh_form'));
            this.form.parse();
            this.id = xhTool.getQuery('id');
            this.listener();
        },
        listener:function () {
            var $this = this;
            //保存事件
            $('#bt_modal_confirm',parent.document).click(function () {
                $this.funObj().submitForm();
            })
        },
        funObj:function () {
            var $this = this;
            return {
                getModifyData:function () {
                    var subObj = {};
                    if ($('[name=iProdId]').length > 0) {
                        subObj.iProdId = $('[name=iProdId]').val();
                    }
                    if ($('.mTabletShell').length > 0) {
                        var mTab = [];
                        $('.mTabletShell').each(function () {
                            mTab.push({
                                prodId: $(this).find('[name=prodId]').val(),
                                iNum: $(this).find('[name=iNum]').val()
                            })
                        });
                        subObj.mTabletShell = mTab;
                    }
                    if ($('.mTchCode').length > 0) {
                        var mTchCode = {};
                        $('.mTchCode').each(function () {
                            var index = $(this).attr('indexId');
                            mTchCode[index] = {
                                iProdId: $(this).find('[name=prod]').val(),
                                code: $(this).find('[name=code]').val()
                            }
                        });
                        subObj.mTchCode = mTchCode;
                    }
                    return subObj;
                },
                submitForm:function () {
                    var data = $this.funObj().getModifyData();
                    data.id = $this.id;
                    xhExtra.ajaxRequest('device/saveApModify', data, {}, function (res) {
                        window.top.xhTop.showSuccess(res.msg);
                        window.top.xhTop.getActiveFrame().obj.dataGrid.reload();
                        window.top.xhTop.closeModal();
                    })
                }
            }
        }
    }
};